package com.alibaba.dubbo.remoting.msgcodec;

import com.alibaba.dubbo.common.configure.ExtensionConfiguratorUtils;
import com.alibaba.dubbo.common.io.Bytes;

public class DES3CodecBase extends DES3Codec {
	private byte []iv;
	private byte []key;
	
	public byte[] getIv() {
		return iv;
	}

	public void setIv(byte[] iv) {
		this.iv = iv;
	}

	public byte[] getKey() {
		return key;
	}

	public void setKey(byte[] key) {
		this.key = key;
	}

	public DES3CodecBase(){
		//iv = new byte[]{1, 72, 2, 95, 79, 53, 83, 89};
		ExtensionConfiguratorUtils instance = ExtensionConfiguratorUtils.getInstance();
		String name = ExtensionConfiguratorUtils.combine(DES3Codec.class, "iv");
		Object value = instance.getValue(name);
		if(value == null){
			iv = new byte[]{1, 72, 2, 95, 79, 53, 83, 89};
		}else if(value instanceof byte[]){
			iv = (byte[])value;
		}else{
			iv = Bytes.base642bytes(value.toString());
		}
		
		name = ExtensionConfiguratorUtils.combine(DES3Codec.class, "key");
		value = instance.getValue(name);
		if(value == null){
			key = new byte[]{49, 32, 97, 109, 32, 115, 111, 114, 114, 121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		}else if(value instanceof byte[]){
			key = (byte[])value;
		}else{
			key = Bytes.base642bytes(value.toString());
		}
	}
}
